package com.itheima.service.impl;

import com.itheima.dao.SysDictTypeDao;
import com.itheima.pojo.SysDictType;
import com.itheima.service.SysDictTypeService;
import com.itheima.vo.SysDictTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysDictTypeServiceImpl implements SysDictTypeService {

    @Autowired
    private SysDictTypeDao sysDictTypeDao;

    /**
     * 添加字典类型
     *@param sysDictTypeVO
     * @return void
     *@author itheima
     */
    @Override
    public void add(SysDictTypeVO sysDictTypeVO) {
        SysDictType sysDictType = new SysDictType();
        sysDictType.setDictName(sysDictTypeVO.getDictName());
        sysDictType.setDictType(sysDictTypeVO.getDictType());
        sysDictType.setIsPublish(sysDictTypeVO.getIsPublish());
        sysDictType.setOid(sysDictTypeVO.getOid());
        sysDictType.setRemark(sysDictTypeVO.getRemark());
        sysDictType.setSort(sysDictTypeVO.getSort());
        sysDictType.setStatus(String.valueOf(sysDictTypeVO.getStatus()));
        sysDictType.setUid(sysDictTypeVO.getUid());

        sysDictTypeDao.insertSelective(sysDictType);
    }

    /**
     * 批量删除字典类型
     *@param sysDictTypeVOList
     * @return void
     *@author itheima
     */
    @Override
    public void deleteBatch(List<SysDictTypeVO> sysDictTypeVOList) {
        SysDictType sysDictType = new SysDictType();
        if (sysDictTypeVOList != null || sysDictTypeVOList.size() >0 ) {
            for (SysDictTypeVO sysDictTypeVO : sysDictTypeVOList) {
                if (sysDictTypeVO.getUid() != null) {
                    sysDictType.setUid(sysDictTypeVO.getUid());
                    sysDictTypeDao.deleteByPrimaryKey(sysDictType.getUid());
                }
            }
        }
    }

    /**
     * 编辑字典类型
     *@param sysDictTypeVO
     * @return void
     *@author itheima
     */
    @Override
    public void edit(SysDictTypeVO sysDictTypeVO) {
        SysDictType sysDictType = new SysDictType();
        sysDictType.setDictName(sysDictTypeVO.getDictName());
        sysDictType.setDictType(sysDictTypeVO.getDictType());
        sysDictType.setIsPublish(sysDictTypeVO.getIsPublish());
        sysDictType.setOid(sysDictTypeVO.getOid());
        sysDictType.setRemark(sysDictTypeVO.getRemark());
        sysDictType.setSort(sysDictTypeVO.getSort());
        sysDictType.setStatus(String.valueOf(sysDictTypeVO.getStatus()));
        sysDictType.setUid(sysDictTypeVO.getUid());

        sysDictTypeDao.updateByPrimaryKeySelective(sysDictType);
    }

    /**
     * 获取字典类型列表
     *@param sysDictTypeVO
     * @return java.util.List<com.itheima.pojo.SysDictType>
     *@author itheima
     */
    @Override
    public List<SysDictType> getList(SysDictTypeVO sysDictTypeVO) {
        List<SysDictType> sysDictTypes = sysDictTypeDao.selectAll();
        return sysDictTypes;
    }


}
